/**
 * 
 */
package com.struts2.show.imageResize;



/**
 * @author MartinChen
 * 
 */
public class ImageResizeAction{

	private String imageFileName;
	private String errorMessage;
	private double width;
	private double height;
	
	public String execute() throws Exception {
	
		return validater()==true?"success":"error";
	}
	
	public boolean validater(){
		
		if(imageFileName==null||imageFileName.trim().equals("")){
			errorMessage = "image filename can not be null!";
			return false;
		}
		
		if(imageFileName.indexOf(".jpg")!=-1||imageFileName.indexOf(".gif")!=-1
				||imageFileName.indexOf(".png")!=-1||imageFileName.indexOf(".bmp")!=-1){
			
		}else{
			errorMessage = "please enter a valid image filename!";
			return false;
		}
		
		if(width<=0||width>2000){
			errorMessage = "please enter a valid image width! 1 ~ 2000";
			return false;
		}
		
		if(height<=0||height>2000){
			errorMessage = "please enter a valid image height! 1 ~ 2000";
			return false;
		}
		
		
		return true;
	}
	
	
	
	public String getImageFileName() {
		return imageFileName;
	}
	
	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}
	
	public double getWidth() {
		return width;
	}
	
	public void setWidth(double width) {
		this.width = width;
	}
	
	public double getHeight() {
		return height;
	}
	
	public void setHeight(double height) {
		this.height = height;
	}
	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	

}
